const Router = require('koa-router')
const { User } = require('../../models/user')

const { isInt, isRegister } = require('../../validators')
const { success } = require('../../../core/http-exception')
const router = new Router({
    prefix: '/api'
})

// router.get('/',async ctx => {
//     const v = await new isInt().validate(ctx)
//     ctx.body = "shouye"
// })

router.post('/register',async ctx=>{
   
    const v = await new isRegister().validate(ctx)
    const user = {
        nickName:v.get('body.nickName'),
        email:v.get('body.email'),
        password:v.get('body.password'),
    }
    const response = await User.create(user)
    throw new success({
        response
    })
})

router.get('/list',async ctx=>{
    let auth = ctx.auth
    throw new success({
        response:auth
    })
})
module.exports = router